package com.qf.controller;

import com.qf.constant.CookieConstant;
import com.qf.constant.RedisConstant;
import com.qf.dto.ResultBean;
import com.qf.service.IUserService;
import com.qf.util.StringUtil;
import javafx.print.PaperSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.ReactiveStreamCommands;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by IntelliJ IDEA.
 * User: dong
 * Date: 2020/3/12
 */
@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    private IUserService userService;

    //邮箱注册
    @RequestMapping("registerByEmail")
    @ResponseBody
    public ResultBean registerByEmail(String email, String password){
        return userService.registerByEmail(email,password);
    }

    //激活用户
    @RequestMapping("emailActive")
    @ResponseBody
    public ResultBean emailActive(String email){
        return userService.emailActive(email);
    }

    //发送手机验证码
    @RequestMapping("getCode")
    @ResponseBody
    public ResultBean getCode(String phone){
        //使用mq让第三方短信服务商来发送短信
        userService.getCode(phone);
        return ResultBean.success();
    }

    //手机号注册
    @RequestMapping("registerByPhone")
    @ResponseBody
    public ResultBean registerByPhone(String phone,String code,String password){
        return userService.registerByPhone(phone,code,password);
    }

    //登录校验
    @RequestMapping("checkLogin")
    @ResponseBody
    public ResultBean checkLogin(String uname,String password){
        return userService.checkLogin(uname,password);
    }

    //根据uuid去redis查询有无相应登录信息
    @RequestMapping("checkIsLogin")
    @ResponseBody
    public ResultBean checksLogin(String uuid){
        return userService.checkIsLogin(uuid);
    }



}
